package model;

import javax.persistence.*;
import java.util.Date;

@NamedQueries({
        @NamedQuery(name = "Leave.getAll", query = "SELECT l FROM Leave l"),
        @NamedQuery(name = "Leave.getById", query = "SELECT l FROM Leave l WHERE l.id = :id"),
        @NamedQuery(name = "Leave.getByUserId", query = "SELECT l FROM Leave l WHERE l.user.id = :uid")
})
@Entity
@Table(name = "rmt_leave")
public class Leave {
    private int id;
    private User user;
    private Date from;
    private Date until;
    private String reason;
    private LeaveType type;
    private LeaveStatus status;

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name = "id")
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Temporal(value =  TemporalType.DATE)
    @Column(name = "from_date")
    public Date getFrom() {
        return from;
    }

    public void setFrom(Date from) {
        this.from = from;
    }

    @Temporal(value =  TemporalType.DATE)
    @Column(name = "until_date")
    public Date getUntil() {
        return until;
    }

    public void setUntil(Date until) {
        this.until = until;
    }

    @Basic
    @Column(name = "reason")
    public String getReason() {
        return reason;
    }

    public void setReason(String reason) {
        this.reason = reason;
    }

    @ManyToOne(targetEntity = LeaveType.class)
    @JoinColumn(name = "type_id")
    public LeaveType getType() {
        return type;
    }

    public void setType(LeaveType type) {
        this.type = type;
    }

    @ManyToOne
    @JoinColumn(name = "status_id")
    public LeaveStatus getStatus() {
        return status;
    }

    public void setStatus(LeaveStatus status) {
        this.status = status;
    }

    @ManyToOne(targetEntity = User.class)
    @JoinColumn(name = "user_id")
    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }


}
